package sol.leetcode;

import def.TreeNode;

/**
 * Kth Smallest Element in a BST
 */
public class Issue230 {
    TreeNode res;
    int count;

    public int kthSmallest(TreeNode root, int k) {
        find(root, k);
        return res.val;
    }

    private void find(TreeNode root, int k) {
        if (root == null)
            return;
        find(root.left, k);

        if (++count == k) {
            res = root;
            return;
        }

        find(root.right, k);
    }

    public static void main(String[] args) {
        TreeNode n1 = new TreeNode(1);
        TreeNode n2 = new TreeNode(2);
        TreeNode n3 = new TreeNode(3);
        TreeNode n4 = new TreeNode(4);


    }

}
